<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>bitcola ico审核</title>
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
    <script>

        new WebSocket('wss://bitcola.top/ws');
        const baseUrl = 'http://112.74.59.207:8765';
        let token = '';
        var data = {};
        $(function () {

            $('#login').on('click', function () {
                $.ajax({
                    url: baseUrl + '/api/me/colaUser/login',
                    type: 'post',
                    contentType: 'application/json',
                    processData: false,
                    data: JSON.stringify({
                        username: $('#username').val(),
                        password: $('#password').val()
                    }),
                    success: function (resp) {
                        if (resp.status === 200) {
                            token = resp.data;
                            alert('登录成功');
                        }
                    }
                })
            })
            $('#load').on('click', function () {
                if (token === '') {
                    alert('请登录');
                } else {
                    $.ajax({
                        url: baseUrl + '/api/me/ico/getAllIcoUser',
                        type: 'get',
                        headers: {
                            Authorization: token
                        },
                        success: function (data) {
                            if (data.status === 200) {
                                console.log(data);
                                data = data.data;
                                console.log(data.length);
                                var tr = '';
                                for (var i = 0; i < data.length; i++) {
                                    tr += '<tr><td>' + data[i].id + '</td><td>' + data[i].userId + '</td><td>' + data[i].firstName + '</td><td>' + data[i].lastName + '</td> <td>' + data[i].gender + '</td><td>' + data[i].birthday + '</td><td>' + data[i].email + '</td><td>' + data[i].areaCode + data[i].telPhone + '</td><td>' + data[i].plannedInvestment + '</td><td>' + data[i].country + '</td><td>' + data[i].idCardType + '</td><td>' + '<a target="_blank" href="http://112.74.59.207:8765/api/me/colaImage/get?name=' + data[i].frontSide + '">正面</a>' + '</td><td>' + '<a target="_blank" href="http://112.74.59.207:8765/api/me/colaImage/get?name=' + data[i].backSide + '">反面</a>' + '</td><td>' + data[i].checkStatus + '</td>' +
                                        '<td>' + data[i].depositAddress + '</td><td><p><button class="agree">通过</button></p><p><button class="refuse">拒绝</button></p></td></tr>'
                                }
                                document.getElementById("tbody").innerHTML = tr;
                                $('.agree').on('click', function () {
                                    let id = $(this).closest('tr').find('td').eq(0).text();
                                    var requstdata = {
                                        "id": id,
                                        "option": "agree"
                                    };
                                    $.ajax({
                                        url: baseUrl + '/api/me/ico/audit',
                                        type: 'post',
                                        headers: {
                                            Authorization: token
                                        },
                                        data: JSON.stringify(requstdata),
                                        contentType: 'application/json',
                                        processData: false,
                                        success: function (data) {
                                            alert(data.message);
                                        }
                                    })
                                })
                                $('.refuse').on('click', function () {
                                    let id = $(this).closest('tr').find('td').eq(0).text();
                                    var requstdata = {
                                        "id": id,
                                        "option": "refuse"
                                    };
                                    $.ajax({
                                        url: baseUrl + '/api/me/ico/audit',
                                        type: 'post',
                                        headers: {
                                            Authorization: token
                                        },
                                        data: JSON.stringify(requstdata),
                                        contentType: 'application/json',
                                        processData: false,
                                        success: function (data) {
                                            alert(data.message);
                                        }
                                    })
                                })
                            }
                            else {
                                alert(data.message + data.status);
                            }
                        }
                    })
                }
            })
        })


    </script>
    <style>
        .header {
            margin: 10px auto;
            width: 50%;
        }

        input[type="text"] {
            padding: 3px 8px;
            border-radius: 3px;
        }

        table {
            width: 100%;
            border-collapse: collapse;
        }

        td, th {
            font-size: 1em;
            border: 1px solid #3c4146;
            padding: 3px 7px 2px 7px;
        }

        th {
            font-size: 1.1em;
            text-align: left;
            padding-top: 5px;
            padding-bottom: 4px;
            background-color: #303134;
            color: #ffffff;
        }

        tr, td {
            color: #000000;
            background-color: #e2e2e2;
            word-break: break-all;
        }

        tbody tr:hover {
            background-color: #303134;
            color: #ffffff;
        }

        p {
            width: 40px;
        }

        a {
        }
    </style>
</head>
<body>
<div class="header">
    <input id="username" value="woaishenhua115@163.com">
    <input id="password" value="123456">
    <button id="login">登录</button>
    <button id="load">加载 ico 数据</button>
</div>
<table>
    <thead>
    <tr>
        <th>id</th>
        <th>用户 ID</th>
        <th>firstName</th>
        <th>lastName</th>
        <th>性别</th>
        <th>生日</th>
        <th>邮箱</th>
        <th>区号+手机号</th>
        <th>预计充值数量</th>
        <th>国家</th>
        <th>证件类型</th>
        <th>证件前面</th>
        <th>证件后面</th>
        <th>是否通过</th>
        <th>充值地址</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody id="tbody">
    </tbody>
</table>
<div>
</div>
</body>
</html>